
#include <asm.h>

.global C_SYMBOL(ResizeBilinear_8u_P4)

C_SYMBOL(ResizeBilinear_8u_P4):
srcy_16= -0x48
y= -0x44
yrIntFloat_16= -0x40
xrIntFloat_16= -0x3C
DstPitch= -0x38
DstHeight= -0x34
DstWidth= -0x30
DstA= -0x2C
DstB= -0x28
DstG= -0x24
DstR= -0x20
SrcPitch = -0x1C
SrcHeight = -0x18
SrcWidth= -0x14
SrcA= -0x10
SrcB= -0xC
SrcG= -0x8
SrcR= -0x4

    STMFD	SP!, {R4-R12,LR}
    SUB     SP, SP, #0x4C
Start:
//.long 0xe7fddefe
    LDR     R4, [R0,#0x0]
    STR     R4, [SP,#0x4C+SrcR]

    LDR     R5, [R0,#0x4]
    STR     R5, [SP,#0x4C+SrcG]

    LDR     R4, [R0,#0x8]
    STR     R4, [SP,#0x4C+SrcB]

    LDR     R5, [R0,#0xC]
    STR     R5, [SP,#0x4C+SrcA]

    LDR     R4, [R0,#0x10]
    STR     R4, [SP,#0x4C+SrcWidth]

    LDR     R4, [R0,#0x14]
    STR     R4, [SP,#0x4C+SrcHeight]

    LDR     R11, [R0,#0x18]
    STR     R11, [SP,#0x4C+SrcPitch]

    LDR     R6, [R1,#0x0]
    STR     R6, [SP,#0x4C+DstR]

    LDR     R7, [R1,#0x4]
    STR     R7, [SP,#0x4C+DstG]

    LDR     R8, [R1,#0x8]
    STR     R8, [SP,#0x4C+DstB]

    LDR     R9, [R1,#0xC]
    STR     R9, [SP,#0x4C+DstA]

    LDR     R4, [R1,#0x10]
    STR     R4, [SP,#0x4C+DstWidth]

    LDR     R12, [R1,#0x18]
    STR     R12, [SP,#0x4C+DstPitch]

    SUB     R4, R12, R4
    TMCR    wCGR1, R4

    LDR     R4, [R1,#0x14]
    STR     R4, [SP,#0x4C+DstHeight]

    //STR     R2, [SP,#0x4C+xrIntFloat_16]
    TMCR    wCGR2, R2
    STR     R3, [SP,#0x4C+yrIntFloat_16]

    LDR	R1, =0x00000010
    TMCRR   wR15 , R1, R1

    MOV	R4, #0

    STR	R4, [SP,#0x4C+srcy_16]

    LDR	R3, [SP,#0x4C+DstHeight]
    CMP	R3, #0
    BLS	Done

    LDR	LR, =0xFFFF


Header:

    LDR	R1, [SP,#0x4C+srcy_16]
    AND	R3, R1,	LR
    MOV	R3, R3,LSR#8
    TMCR   wCGR0, R3                \\ wCGR0 = v_8

    MOV	R4, R1,LSR#16

    LDR R0, [SP,#0x4C+SrcR]
    MLA	R0, R4,	R11, R0

    LDR R1, [SP,#0x4C+SrcG]
    MLA	R1, R4,	R11, R1

    LDR R2, [SP,#0x4C+SrcB]
    MLA	R2, R4,	R11, R2

    LDR R3, [SP,#0x4C+SrcA]
    MLA	R3, R4,	R11, R3

    LDR	R10, [SP,#0x4C+DstWidth]

    TMCRR   wR12, R0, R1
    TMCRR   wR13, R2, R3

    MOV R12, #0
    CMP	R10, #0
    BLE Done

LoopX:
@.long 0xe7fddefe

    TMRC   R0, wCGR0

    AND	R1, R12, LR
    MOV	R1, R1,LSR#8

    MUL R3, R0, R1
    RSB R2, R3, R1,LSL  #8
    RSB R1, R3, R0,LSL  #8
    SUB R0, LR, R3
    SUB R0, R0, R2
    SUB R0, R0, R1

    ORR R0, R0, R1,LSL #16
    ORR R2, R2, R3,LSL #16
    TMCRR   wR0 , R0, R2

    TMRRC   R0, R5 ,wR12

    MOV	    R2, R12,LSR#16
    ADD	    R0, R0, R2

    LDRB R1, [R0]
    LDRB R2, [R0, #1]

    ADD	R0, R0,	R11

    LDRB R3, [R0]
    LDRB R4, [R0, #1]

    ORR  R1,R1,R3,LSL #8
    ORR  R3,R2,R4,LSL #8
    ORR  R1,R1,R3,LSL #16

    TMCRR  wR1, R1, R3
    WUNPCKELUB wR1,wR1
    WMACUZ  WR1, WR1, WR0

    MOV	    R2, R12,LSR#16
    ADD	    R5, R5, R2

    LDRB R1, [R5]
    LDRB R2, [R5, #1]

    ADD	R5, R5,	R11

    LDRB R3, [R5]
    LDRB R4, [R5, #1]

    WSRLD   wR1,wR1,wR15
    WSTRB	wR1, [R6], #1

    ORR  R1,R1,R3,LSL #8
    ORR  R3,R2,R4,LSL #8
    ORR  R1,R1,R3,LSL #16
    TMCRR  wR2, R1, R3

    WUNPCKELUB wR2,wR2
    WMACUZ  WR2, WR2, WR0

    TMRRC   R0, R5 ,wR13
    MOV	    R2, R12,LSR#16
    ADD	    R0, R0, R2

    LDRB R1, [R0]
    LDRB R2, [R0, #1]

    ADD	R0, R0,	R11

    LDRB R3, [R0]
    LDRB R4, [R0, #1]

    WSRLD   wR2,wR2,wR15
    WSTRB	wR2, [R7], #1

    ORR  R1,R1,R3,LSL #8
    ORR  R3,R2,R4,LSL #8
    ORR  R1,R1,R3,LSL #16

    TMCRR  wR3, R1, R3
    WUNPCKELUB wR3,wR3
    WMACUZ  WR3, WR3, WR0

    MOV	    R2, R12,LSR#16
    ADD	    R5, R5, R2
    LDRB R1, [R5]
    LDRB R2, [R5, #1]

    ADD	R5, R5,	R11

    LDRB R3, [R5]
    LDRB R4, [R5, #1]

    WSRLD   wR3,wR3,wR15
    WSTRB	wR3, [R8], #1

    ORR  R1,R1,R3,LSL #8
    ORR  R3,R2,R4,LSL #8
    ORR  R1,R1,R3,LSL #16
    TMCRR  wR4, R1, R3

    WUNPCKELUB wR4,wR4
    WMACUZ  WR4, WR4, WR0

    TMRC   R0, wCGR2

    SUB R10, R10, #1
    CMP R10, #0
    ADD R12, R12, R0

    WSRLD   wR4,wR4,wR15
    WSTRB	wR4, [R9], #1

    BGT	LoopX

NextLine:
//.long 0xe7fddefe
    LDR	R1, [SP,#0x4C+srcy_16]
    LDR	R2, [SP,#0x4C+yrIntFloat_16]
    ADD	R1, R1,	R2
    STR	R1, [SP,#0x4C+srcy_16]

    AND	R3, R1,	LR
    MOV	R3, R3,LSR#8
    TMCR   wCGR0, R3                \\ wCGR0 = v_8

    TMRC R5, wCGR1
    MOV	R4, R1,LSR#16

    LDR R0, [SP,#0x4C+SrcR]
    ADD R6, R6, R5
    MLA	R0, R4,	R11, R0

    LDR R1, [SP,#0x4C+SrcG]
    ADD R7, R7, R5
    MLA	R1, R4,	R11, R1

    LDR R2, [SP,#0x4C+SrcB]
    ADD R8, R8, R5
    MLA	R2, R4,	R11, R2

    LDR R3, [SP,#0x4C+SrcA]
    ADD R9, R9, R5
    MLA	R3, R4,	R11, R3

    LDR	R10, [SP,#0x4C+DstWidth]
    LDR	R4, [SP,#0x4C+DstHeight]

    TMCRR   wR12, R0, R1
    TMCRR   wR13, R2, R3

    SUB R4, R4, #1
    MOV R12, #0
    STR	R4, [SP,#0x4C+DstHeight]
    CMP R4, #0
    BGT  LoopX

Done:
    ADD	SP, SP,	#0x4C
    LDMFD	SP!, {R4-R12,PC}

